﻿var textareaWin = null;
$.extend($.fn.datagrid.defaults.editors, {
  textarea: {//textarea就是你要自定义editor的名称
    init: function (container, options) {
      var me = this;
      var cur = $('<input id="inputID"/>');

      $('<div id="win"><textarea style="width:327px;height:137px;border:none;" id="textareaID" class="datagrid-editable-input"></textarea></div>').appendTo($("body"));
      var editor = cur.appendTo(container);
      $(cur).focus(function () {
        if (!textareaWin) {

          $("#textareaID").val($("#inputID").val());

          textareaWin = $('#win').dialog({
            title: '文本编辑',
            width: 350,
            height: 220,
            closable: false,
            resizable: false,
            closed: false,
            collapsible: false,
            maximizable: false,
            minimizable: false,
            modal: true,
            buttons: [{
              text: '保存',
              iconCls: 'icon-save',
              handler: function () {
                var textVal = $("#textareaID").val();

                $("#inputID").val(textVal);

                textareaWin.window('close');
                textareaWin = undefined;
              }
            }, {
              iconCls: 'icon-cancel',
              text: '取消',
              handler: function () {
                //$.messager.confirm('【提示信息】', '是否确认退出编辑？', function (r) {
                //  if (r) {
                //    textareaWin.window('close');
                //    textareaWin = undefined;
                //  }
                //});
                textareaWin.window('close');
                textareaWin = undefined;
              }
            }]
          });

          $("#textareaID").focus();
        }
      });
      console.log("init method invoke!");
      editor.enableEdit = false;
      return editor;
    },
    getValue: function (target) {
      return $(target).val();
    },
    setValue: function (target, value) {
      $(target).val(value);
    },
    resize: function (target, width) {
      console.log("resize method invoke!");
    },
    destroy: function (target) {
      console.log("destroy method invoke!");
      textareaWin = undefined;
    }
  }
});